using Spring.Context.Support;
using Spring.Objects.Factory.Support;
using System;
namespace AppToolKit.Core.Context.Spring.AutoConstruction.Builder
{
	public class ServiceServerBuilder : ServerBuilderBase
	{
		private ServiceBuildSupport support_ = new ServiceBuildSupport();
		protected override string GetBusinessName(Type businessType)
		{
			return BusinessNameSymbol.GetBusinessName(businessType.FullName);
		}
		public override bool IsSupport(Type type)
		{
			return this.support_.IsSupport(type);
		}
		protected override void RegisterBusiness(Type businessType)
		{
			DefaultListableObjectFactory defaultListableObjectFactory = (DefaultListableObjectFactory)((XmlApplicationContext)base.ApplicationContext).ObjectFactory;
			string businessName = this.GetBusinessName(businessType);
			if (base.ConstructionLocation.ContainImplement(businessType))
			{
				Type implementType = base.ConstructionLocation.GetImplementType(businessType);
				RootObjectDefinition rootObjectDefinition = new RootObjectDefinition(implementType);
				ServiceImplAttribute serviceImplAttribute = (ServiceImplAttribute)implementType.GetCustomAttributes(typeof(ServiceImplAttribute), false)[0];
				rootObjectDefinition.IsSingleton=serviceImplAttribute.Singleton;
				defaultListableObjectFactory.RegisterObjectDefinition(businessName, rootObjectDefinition);
				return;
			}
			throw new AutoConstructionException(string.Format("自动构造找不到相关的实现{0}", businessType));
		}
	}
}
